package handler

import (
	"github.com/gin-gonic/gin"
	"sys-proj-man/model"
)

func Add(c *gin.Context) {
	name := c.PostForm("name")
	title := c.PostForm("title")
	counter := c.PostForm("counter")
	if name == "" || title == "" || counter == "" {
		c.JSON(400, gin.H{
			"code": 500,
			"msg":  "参数不能为空",
		})
	}
	article := model.Article{
		Name:    name,
		Title:   title,
		Counter: counter,
	}
	err := model.DB.Create(&article).Error
	if err != nil {
		c.JSON(400, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
}
func List(c *gin.Context) {
	var article []*model.Article
	model.DB.Debug().Find(&article)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": article,
	})
}
